<template>
	<view class="leave-container">
		<view class="leave-list">
			<view class="leave-item"v-for="(item, index) in leaveList" :key="item.id">
				<view class="leave-item-l">
					<view class="leave-img">
						<image :src="item.user.avatar" mode="aspectFill"></image>
					</view>
					<view class="leave-detail">
						<view class="">{{item.user.nickname}}提交的请假申请</view>
						<view class="con-text">请假类型：{{item.type_name}}</view>
						<view class="con-text">请假原因：{{item.reason}}</view>
						<view class="con-text">请假时间：{{item.leave_time}}</view>
						<view :class="'status leave-'+item.status">{{item.status_name}}</view>
					</view>
				</view>
				<view class="leave-item-r">
					{{item.verify_time.substring(0,10)}}
				</view>
			</view>
			<uni-load-more :status="loadStatus"></uni-load-more>
		</view>
		
		<tabbar :current="1"></tabbar>
	</view>
</template>

<script>
	import { appLogin, msg, httpGet, httpPost } from '@/utils/common.js';
	export default {
		data() {
			return {
				userInfo: {},
				leaveList: [],
				page: 1,
				page_size: 10,
				loadStatus: 'more'
			}
		},
		onLoad(options) {
			appLogin(res => {
				this.userInfo = res;
				this.getLeaveList();
			})
		},
		onReachBottom() {
			if (this.loadStatus === 'nomre') {
				return
			}
			this.page++;
			this.getLeaveList();
		},
		methods: {
			getLeaveList() {
				httpGet({
					url: 'users/leave/my_list',
					data: {
						page: this.page,
						// page_size: this.page_size
					}
				}).then(res => {
					let {count, list} = res.result;
					
					this.loadStatus = 'more';
					let totalPage = Math.ceil(count / this.page_size);
					if (this.page >= totalPage) {
						this.loadStatus = 'nomore';
					}
					if (!list || !list.length) {
						this.loadStatus = 'nomore';
					}
					if (this.page == 1) {
						this.leaveList = list;
					} else {
						this.leaveList = [...this.leaveList, ...list];
					}
				})
			},
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f6f6f6;
	}
	.leave-container {
		.leave-list {
			
			margin-top: 20rpx;
			.leave-item {
				background-color: #fff;
				padding: 30rpx 20rpx;
				margin-top: 10rpx;
				display: flex;
				justify-content: space-between;
				.leave-item-l {
					display: flex;
					
					.leave-img {
						height: 100rpx;
						width: 100rpx;
						margin-right: 20rpx;
						image {
							height: 100rpx;
							width: 100rpx;
							border-radius: 50%;
						}
					}
					.leave-detail {
						.con-text {
							font-size: 26rpx;
							color: #999;
							margin: 5rpx;
						}
						.status {
							font-size: 26rpx;
						}
						.leave-0 {
							color: blue;
						}
						.leave-1 {
							color: green;
						}
						.leave-2 {
							color: red;
						}
					}
				}
				.leave-item-r {
					font-size: 26rpx;
				}
			}
		}
	}
</style>
